import 'package:flutter/material.dart';
import 'package:flutter_color_plugin/flutter_color_plugin.dart';
import 'package:yw_bapp/widgets/wrap_gesture_widget.dart';

class OptionalWidget extends StatelessWidget {
  final Color bgColor; //背景色
  final String leadingImg; //图片
  final String leadingText; //左侧文字
  final String actionText; //右侧文字
  final IconData actionIcon; //右侧Icon
  final double imgWidth;
  final double imgHeight;
  final double iconSize;
  final TextStyle actionStyle;
  final Color iconColor;
  final Function callBack;
  final bool iconShow;

  const OptionalWidget(
      {Key key,
      this.bgColor = Colors.white,
      this.leadingImg,
      this.leadingText,
      this.actionText,
      this.actionIcon = Icons.navigate_next,
      this.imgWidth = 22,
      this.imgHeight = 22,
      this.iconSize = 13,
      this.actionStyle,
      this.iconColor,
      this.callBack,
      this.iconShow = true})
      : super(key: key);
  @override
  Widget build(BuildContext context) {
    bool isNetWork =
        leadingImg?.indexOf("http") != -1 ?? false ? true : false; //判断是不是网络图片路径
    return Container(
      padding: EdgeInsets.fromLTRB(15, 15, 15, 15),
      color: bgColor,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Expanded(
            flex: 1,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                leadingImg != null
                    ? isNetWork
                        ? Image.network(
                            "${leadingImg}",
                            width: imgWidth,
                            height: imgHeight,
                            fit: BoxFit.cover,
                          )
                        : Image.asset(
                            "${leadingImg}",
                            width: imgWidth,
                            height: imgHeight,
                            fit: BoxFit.cover,
                          )
                    : Container(
                        child: null,
                      ),
                Container(
                  margin: EdgeInsets.only(left: leadingImg != null ? 8 : 0),
                  child: DefaultTextStyle(
                    child: Text('${leadingText}'),
                    style: TextStyle(
                        color: ColorUtil.color("#FF333333"), fontSize: 15),
                  ),
                )
              ],
            ),
          ),
          Expanded(
            flex: 1,
            child: wrapGesture(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: [
                  LimitedBox(
                    maxWidth: 60,
                    child: DefaultTextStyle(
                      child: Text(
                        "${actionText ?? ''}",
                        style: actionStyle,
                      ),
                      overflow: TextOverflow.ellipsis,
                      style: TextStyle(
                          color: ColorUtil.color("#FF999999"), fontSize: 15),
                    ),
                  ),
                  iconShow
                      ? Icon(
                          actionIcon,
                          size: 22,
                          color: iconColor ?? ColorUtil.color("#FF999999"),
                        )
                      : Text(""),
                ],
              ),
              function: callBack,
            ),
          )
        ],
      ),
    );
  }
}
